/********************************************************************************
 *    Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH    *
 *                                                                              *
 *              This software is distributed under the terms of the             * 
 *              GNU Lesser General Public Licence (LGPL) version 3,             *  
 *                  copied verbatim in the file "LICENSE"                       *
 ********************************************************************************/
#ifndef ETFNEUTRONWALL_H
#define ETFNEUTRONWALL_H

#include "FairDetector.h"

#include "TVector3.h"
#include "TLorentzVector.h"
class EtfNeutronWallFirstHits;
class EtfNeutronWallPoint;
class FairVolume;
class TClonesArray;

class EtfNeutronWall: public FairDetector
{

  public:

    /**      Name :  Detector Name
     *       Active: kTRUE for active detectors (ProcessHits() will be called)
     *               kFALSE for inactive detectors
    */
    /**      default constructor    */
    EtfNeutronWall();
    EtfNeutronWall(const char* Name, Bool_t Active);

    /**       destructor     */
    virtual ~EtfNeutronWall();

    /**      Initialization of the detector is done here    */
    virtual void   Initialize();

    /**       this method is called for each step during simulation
     *       (see FairMCApplication::Stepping())
    */
    virtual Bool_t ProcessHits( FairVolume* v=0);
    
    /**       Registers the produced collections in FAIRRootManager.     */
    virtual void   Register();

    /** Gets the produced collections */
    virtual TClonesArray* GetCollection(Int_t iColl) const ;

    /**      has to be called after each event to reset the containers      */
    virtual void   Reset();

    /**      Create the detector geometry        */
    void ConstructGeometry();



    /**      This method is an example of how to add your own point
     *       of type EtfNeutronWallPoint to the clones array
    */
    EtfNeutronWallPoint* AddHit(Int_t trackID, Int_t detID,Int_t id1, Int_t id2,
                            TVector3 posIn,TVector3 pos_out, TVector3 momIn,
                            TVector3 momOut,Double_t time, Double_t length,
                             Double_t eLoss);
                             
    EtfNeutronWallFirstHits* AddHit1(Double_t x0, Double_t y0, Double_t z0, Double_t T0,
                            Double_t x1, Double_t y1, Double_t z1, Double_t T1,
                            Double_t x2, Double_t y2, Double_t z2, Double_t T2,
                            Double_t x3, Double_t y3, Double_t z3, Double_t T3,
                            Double_t x4, Double_t y4, Double_t z4, Double_t T4,
                            Double_t x5, Double_t y5, Double_t z5, Double_t T5);
                            
    /** The following methods can be implemented if you need to make
     *  any optional action in your detector during the transport.
    
    virtual void CopyClones(TClonesArray* cl1, TClonesArray* cl2,
                          Int_t offset);
*/
    virtual void   SetSpecialPhysicsCuts() {;}
    virtual void   BeginEvent();
    virtual void   EndOfEvent();
    virtual void   FinishEvent();
   



    virtual Bool_t CheckIfSensitive(std::string name);
  void ResetParameters();
  private:

    /** Track information to be stored until the track leaves the
    active volume.
    */
    Int_t          fTrackID;           //!  track index
    Int_t          fVolumeID;          //!  volume id
    Int_t          fCopyNo;            //!  copy no

    TLorentzVector fPosIn, fPosOut;    //!  position
    TLorentzVector fMomIn, fMomOut;    //!  momentum
    Double32_t     fTime;              //!  time
    Double32_t     fLength;            //!  length
    Double32_t     fELoss;             //!  energy loss
    Double32_t     fLightYield;        //!  light yield
    /** container for data points */

    TClonesArray*  fEtfNeutronWallPointCollection;  //!
    TClonesArray*  fEtfNeutronWallFirstHits;  //!
  
    TList *flGeoPar; 
    Double_t fBirkC0,fBirkC1,fBirkC2;  //!
    Double_t firstHitX[6];             //! position and time of first our hits
    Double_t firstHitY[6];             //!
    Double_t firstHitZ[6];             //!
    Double_t firstT[6];                //!
    void DefineSensitiveVolumes();
    void Getpripoint();

    ClassDef(EtfNeutronWall,2)
};
inline void EtfNeutronWall::ResetParameters()
{
  fTrackID = fVolumeID =fCopyNo= 0;
  fPosIn.SetXYZM(0.0, 0.0, 0.0, 0.0);
  fPosOut.SetXYZM(0.0, 0.0, 0.0, 0.0);
  fMomIn.SetXYZM(0.0, 0.0, 0.0, 0.0);
  fMomOut.SetXYZM(0.0, 0.0, 0.0, 0.0);
  fTime = fLength = fELoss= fLightYield  = 0;
  
};
#endif //ETFNEUTRONWALL_H
